package cn.pb.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.pb.dao.BlogDao;
import cn.pb.domin.Blog;
import cn.pb.domin.PageBean;
import cn.pb.domin.QueryInfo;
import cn.pb.domin.QueryResult;
import cn.pb.service.BlogService;

@Transactional // 业务层事务管理
@Service
public class BlogServiceImp implements BlogService {
	// dao层对象
	@Autowired
	private BlogDao ud;

	/* (non-Javadoc)
	 * @see cn.pb.service.imp.BlogService#add(cn.pb.domin.Blog)
	 */
	@Override
	public void add(Blog blog) {
		ud.add(blog);
	}

	/* (non-Javadoc)
	 * @see cn.pb.service.imp.BlogService#update(cn.pb.domin.Blog)
	 */
	@Override
	public void update(Blog blog) {
		ud.updateById(blog);
	}

	/* (non-Javadoc)
	 * @see cn.pb.service.imp.BlogService#find(java.lang.String)
	 */
	@Override
	public Blog find(String title) {
		return ud.findByBTitle(title);
	}

	/* (non-Javadoc)
	 * @see cn.pb.service.imp.BlogService#findAll(java.io.Serializable)
	 */
	@Override
	public List<Blog> findAll() {
		return ud.findAll();
	}
	
	public PageBean pageQuery(QueryInfo queryinfo) {
		QueryResult qr =new QueryResult();
		qr.setList(ud.pageQuery(queryinfo));
		qr.setTotalRecord(ud.count());
		PageBean bean = new PageBean();
		bean.setCurrentPage(queryinfo.getCurrentPage());
		bean.setList(qr.getList());
		bean.setPageSize(queryinfo.getPageSize());
		bean.setTotalRecord(qr.getTotalRecord());
		return bean;
	}

}
